package com.zjj.lbw.microservice.gateway.order.gatewayorder.controller;

import com.zjj.lbw.common.bean.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhanglei.zjj
 * @description 微服务-rpc-测试feign生产者
 * @date 2023/7/6 22:03
 */

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {
    /**
     * 根据用户id查询订单信息
     *
     * @param userId
     * @return
     */
    @RequestMapping("/findOrderByUserId/{userId}")
    public R findOrderByUserId(@PathVariable("userId") Integer userId) throws InterruptedException {
        log.info("根据userId:" + userId + "查询订单信息");

        return R.ok().put("orders", userId + ", orderId = no.34413349900011111");
    }

    @GetMapping("/testgateway")
    public String testGateway(HttpServletRequest request) throws Exception {
        log.info("gateWay获取请求头X-Request-color："
                + request.getHeader("X-Request-color"));
        return "success";
    }

    @GetMapping("/testgateway2")
    public String testGateway(@RequestHeader("X-Request-color") String color) throws Exception {
        log.info("gateWay获取请求头X-Request-color：" + color);
        return "success";
    }

    @GetMapping("/testgateway3")
    public String testGateway3(@RequestParam("color") String color) throws Exception {
        log.info("gateWay获取请求参数color:" + color);
        return "success";
    }
}
